# Defines for the Simulator and applications
# Defines.mk.  Generated from Defines.mk.in by configure.

#----------------------------------------------------------------------------
# Get some basic info from configure
#----------------------------------------------------------------------------

SRCDIR := .
SIM_ROOT := /filer1/vol3/class/cs315a-spr11/gxj/315party/PA2/simulator

ARCH_X86 := x86
ARCH_PPC := ppc
ARCH = x86

OS_DARWIN := Darwin
OS_LINUX  := Linux
OS_AIX    := AIX
OS = Linux

USE_LIBBFD = no
LIBOPCODES_DIR = /filer1/vol3/class/cs315a-spr11/cs315a/libopcodes32

#----------------------------------------------------------------------------
# define what programs we will use
#----------------------------------------------------------------------------

CC = gcc
CPP = g++
JAVAC = javac
JAVAH = javah
AS = as
AR = ar
RANLIB = ranlib
CP = cp
MV = mv
RM = rm -f
SED = sed
TOUCH = touch

OPTFLAGS := -O3

#----------------------------------------------------------------------------
# Common variables
#----------------------------------------------------------------------------

DEBUGFLAGS := -ggdb3
WARNINGFLAGS := -Wall -fno-strict-aliasing
ifeq ($(ENABLE_WERROR),true)
	WARNINGFLAGS += -Werror
endif
ifeq ($(ENABLE_LINKERSCRIPT),true)
	LINKERSCRIPT := -T $(SRCDIR)/LINKERSCRIPT.$(ARCH)
else
	LINKERSCRIPT := 
endif

ifeq ($(OS),$(OS_DARWIN))
        LD  		       := g++
	EXTRA_CFLAGS   	       := -force_cpusubtype_ALL
	EXTRA_CPPFLAGS 	       := 
	EXTRA_ASFLAGS  	       := $(DEBUGFLAGS)
	EXTRA_LDFLAGS  	       := -flat_namespace -bind_at_load
	EXTRA_LIBS     	       := 
	EXTRA_GCC_OPTIM2_LABEL := -freorder-functions 
	EXTRA_TESTSRC          := 
	SHLIB_EXT  	       := dylib
	SHLIB_LDFLAGS  	       := -dynamiclib -single_module
	JNI_SHLIB_EXT          := jnilib
	JNI_LDFLAGS            := $(SHLIB_LDFLAGS)
	MAKE_DEPEND_OS_FLAGS   := -D__APPLE__
	ifeq ($(ARCH),$(ARCH_PPC))
		CPU_TYPE := $(shell machine | grep "ppc74[0-9][0-9]" )
	endif
else 
ifeq ($(OS),$(OS_LINUX))
        LD  		       := g++
	EXTRA_CFLAGS   	       := -fPIC -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
	EXTRA_CPPFLAGS 	       := 
	EXTRA_ASFLAGS  	       := -c -Wa,--gstabs+
	EXTRA_LDFLAGS  	       := -rdynamic -Wl,-z,now -L$(SIM_ROOT) $(LINKERSCRIPT)
	EXTRA_LIBS     	       := -ldl -lpthread
	EXTRA_GCC_OPTIM2_LABEL := 
	EXTRA_TESTSRC          := 
	SHLIB_EXT              := so
	SHLIB_LDFLAGS  	       := -shared -Wl,-z,now
	JNI_SHLIB_EXT          := $(SHLIB_EXT)
	JNI_LDFLAGS            := $(SHLIB_LDFLAGS)
	MAKE_DEPEND_OS_FLAGS   := -D__linux__
	ifeq ($(ARCH),$(ARCH_PPC))
		EXTRA_CFLAGS      += -Wa,-mregnames -Wa,-maltivec
		EXTRA_ASFLAGS     += -mregnames
		CPU_TYPE          := $(shell cat /proc/cpuinfo | grep "74[0-9][0-9]")
	endif
	ifeq ($(ARCH),$(ARCH_X86))
		EXTRA_CFLAGS      += -m32 -D_GNU_SOURCE
		EXTRA_ASFLAGS     += -m32
		EXTRA_LDFLAGS     += -m32
		SHLIB_LDFLAGS     += -m32
		JNI_LDFLAGS       += -m32
	endif
else 
ifeq ($(OS),$(OS_AIX))
        CC  		       := gcc32
        CPP 		       := g++
        LD  		       := g++
	AS	   	       := gcc
	EXTRA_CFLAGS   	       := -Wa,-m,any -Wa,-mregnames
	EXTRA_CPPFLAGS 	       := 
	EXTRA_ASFLAGS  	       := -c -Wa,-mregnames
	EXTRA_LDFLAGS  	       := 
	EXTRA_LIBS     	       :=
	EXTRA_GCC_OPTIM2_LABEL := 
	EXTRA_TESTSRC          := 
	SHLIB_EXT              := so
	SHLIB_LDFLAGS  	       := 
	JNI_SHLIB_EXT          := $(SHLIB_EXT)
	JNI_LDFLAGS            := $(SHLIB_LDFLAGS)
	MAKE_DEPEND_OS_FLAGS   := -D_AIX
	CPU_TYPE :=
else 
	$(error unknown system "$(OS)")
endif
endif
endif

ifeq ($(ARCH),$(ARCH_PPC))
        # Detect CPU and set flags appropriately
        # less.cpp has an instruction that does not like G4s
	ifdef CPU_TYPE
		EXTRA_CFLAGS := $(EXTRA_CFLAGS) -D_USING_G4_
	endif
else
ifeq ($(ARCH),$(ARCH_X86))
	EXTRA_CFLAGS := $(EXTRA_CFLAGS) -march=i686
else 
	$(error unknown architecture "$(ARCH)")
endif
endif

ifneq ($(LIBOPCODES_DIR),none)
ifneq ($(LIBOPCODES_DIR),default)
	EXTRA_LIBS += -L$(LIBOPCODES_DIR)/lib
	EXTRA_INCLUDES += -I$(LIBOPCODES_DIR)/include
endif
    EXTRA_LIBS += -lopcodes
ifeq ($(USE_LIBBFD),yes)
	EXTRA_LIBS += -lbfd
endif
endif

ifeq ($(ENABLE_AUTODEPEND),true)
	DEPENDFLAGS := -MMD
else
	DEPENDFLAGS :=
endif

# ==== Flags and other variables ==============================================

# The first line is supposedly -O1 according to the gcc manual, but on
# FC5 using -O1 breaks loops. Fedora must be turning extra options on...
#
# These optimizations break TCC_*Label
#	-fschedule-insns \
#	-fschedule-insns2 \
#	-fgcse \
#	-fgcse-lm \
#	-fgcse-sm \
#
ifeq ($(ARCH),$(ARCH_PPC))
GCC_OPTIM2_LABEL := $(EXTRA_CFLAGS) \
        -fomit-frame-pointer -fdefer-pop -fguess-branch-probability -fcprop-registers -floop-optimize -fif-conversion -fif-conversion2 -ftree-ccp -ftree-dce -ftree-dominator-opts -ftree-dse -ftree-ter -ftree-lrs -ftree-sra -ftree-copyrename -ftree-fre -ftree-ch -fmerge-constants \
	-foptimize-sibling-calls \
	-fstrength-reduce \
	-fcse-follow-jumps \
	-fcse-skip-blocks \
	-frerun-cse-after-loop \
	-frerun-loop-opt \
	-fdelete-null-pointer-checks \
	-fexpensive-optimizations \
	-fregmove \
	-fsched-interblock \
	-fsched-spec \
	-fcaller-saves \
	-fpeephole2 \
	-freorder-blocks \
	-fstrict-aliasing \
	-falign-functions \
	-falign-jumps \
	-falign-loops \
	-falign-labels \
	$(EXTRA_GCC_OPTIM2_LABEL) \
#
GCC_OPTIM3_LABEL := $(GCC_OPTIM2_LABEL) \
	-finline-functions \
	-frename-registers \
#
else
ifeq ($(ARCH),$(ARCH_X86))
GCC_OPTIM2_LABEL := $(EXTRA_CFLAGS) \
	-O1 \
	-foptimize-sibling-calls \
	-fstrength-reduce \
	-fcse-follow-jumps \
	-fcse-skip-blocks \
	-frerun-cse-after-loop \
	-frerun-loop-opt \
	-fdelete-null-pointer-checks \
	-fexpensive-optimizations \
	-fregmove \
	-fsched-interblock \
	-fsched-spec \
	-fcaller-saves \
	-fpeephole2 \
	-freorder-blocks \
	-fstrict-aliasing \
	-falign-functions \
	-falign-jumps \
	-falign-loops \
	-falign-labels \
	$(EXTRA_GCC_OPTIM2_LABEL) \
#
GCC_OPTIM3_LABEL := $(GCC_OPTIM2_LABEL) \
	-finline-functions \
	-frename-registers \
#
else 
	$(error unknown architecture "$(ARCH)")
endif
endif

# -DUSE_DL_PREFIX is for includers of malloc.h
COMMONCFLAGS = $(DEBUGFLAGS) $(WARNINGFLAGS) $(EXTRA_CFLAGS) -DUSE_DL_PREFIX -DSIMULATOR -I$(SRCDIR)/$(ARCH) -I$(SRCDIR)/tm $(INCLUDES) $(EXTRA_INCLUDES) # -save-temps

CFLAGS   = -I. $(COMMONCFLAGS) $(OPTFLAGS) $(DEPENDFLAGS)
CPPFLAGS = $(CFLAGS) $(EXTRA_CPPFLAGS) -fno-threadsafe-statics
ASFLAGS  = $(EXTRA_ASFLAGS)
LDFLAGS  = -Wl,-rpath,/filer1/vol3/class/cs315a-spr11/gxj/315party/PA2/simulator $(EXTRA_LDFLAGS)
LIBS     = -L. -lc -lSim $(EXTRA_LIBS)

# For programs that use TCC_*Label:
CFLAGS_LABEL2 = $(COMMONCFLAGS) $(GCC_OPTIM2_LABEL)
CFLAGS_LABEL3 = $(COMMONCFLAGS) $(GCC_OPTIM3_LABEL)

# If we are invoked from setup-rvm-less.pl, we need to strip the configuration suffix
RVM_BUILD_without_suffix := $(subst _lock,,$(subst _tm,,$(RVM_BUILD)))
ifneq ($(RVM_BUILD),$(RVM_BUILD_without_suffix))
	RVM_BUILD := $(RVM_BUILD_without_suffix)
endif
CLASSPATH := $(RVM_BUILD)_tm/RVM.classes/jksvm.jar:$(RVM_BUILD)_tm/RVM.classes/rvmrt.jar:$(RVM_BUILD)_lock/RVM.classes/jksvm.jar:$(RVM_BUILD)_lock/RVM.classes/rvmrt.jar
JAVACFLAGS := -g
JIKESRVM_OUTPUT  := JNIAddresses.txt disassemble.jit.lock.txt disassemble.jit.tm.txt

JAVAC := javac
JAVAH := javah

LIBSIM := libSim.a
LIBSIM_SH := libSim.$(SHLIB_EXT)

#----------------------------------------------------------------------------
# Variables for use by OpenTM applications
#----------------------------------------------------------------------------
# should be java 1.5 or more recent version
ifeq ($(OS),$(OS_DARWIN))
	$(error Unsupported system "$(OS)")
else 
ifeq ($(OS),$(OS_LINUX))
	ifeq ($(ARCH),$(ARCH_PPC))
		OTM_JAVA_PATH := /usr/local/ibm-java2-ppc-50/bin
	endif
	ifeq ($(ARCH),$(ARCH_X86))
		OTM_JAVA_PATH := /usr/java/jdk1.5.0_09/bin
	endif
else 
ifeq ($(OS),$(OS_AIX))
	$(error Unsupported system "$(OS)")
else 
	$(error unknown system "$(OS)")
endif
endif
endif

OTM_JAVA 	:= $(OTM_JAVA_PATH)/java
OTM_COMPILER	:= cetus.otm.OtmCompiler
OTM_CLASS_PATH	:= $(SIM_ROOT)/../OpenTM/cetus/antlr.jar:../OpenTM
OTM_OUTPUT_DIR	:= ./otm_output/

#----------------------------------------------------------------------------
# Variables for use by all C applications
#----------------------------------------------------------------------------
SIM_INCLUDES    := -I$(SIM_ROOT)/$(SRCDIR) -I$(SIM_ROOT)/$(SRCDIR)/base -I$(SIM_ROOT)/$(SRCDIR)/tm -I$(SIM_ROOT)/$(SRCDIR)/$(ARCH)
SIM_LDFLAGS     := $(LDFLAGS)
SIM_LIBS        := -L$(SIM_ROOT) $(LIBS)
SIM_OUTPUT      := itrace log.sim pid pool.sim profile statistics trace.log violations $(JIKESRVM_OUTPUT) $(OTM_OUTPUT_DIR)

#----------------------------------------------------------------------------
# EOF
#----------------------------------------------------------------------------
